﻿<UserControl x:Class="ScrumPowerTools.Views.ReviewView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:ScrumPowerTools.Framework.Presentation"
             mc:Ignorable="d" d:DesignHeight="200"
             d:DesignWidth="500" Name="ReviewToolWindow">
  <UserControl.Resources>

    <ContextMenu x:Key="ReviewItemMenu"
                 DataContext="{Binding RelativeSource={RelativeSource Mode=Self}, Path=PlacementTarget.DataContext}">
        <MenuItem Header="Open" />
        <MenuItem Header="View History"
                  Command="{Binding Path=DataContext.ViewHistoryCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl} } }"
                  CommandParameter="{Binding}" />
        <MenuItem Header="Changeset Details"
                Command="{Binding Path=DataContext.ViewChangesetDetailsCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl} } }"
                CommandParameter="{Binding}" />
        <MenuItem Header="Compare">
            <MenuItem Header="With Previous Version"
                        Command="{Binding Path=DataContext.CompareWithPreviousVersionCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl} } }"
                        CommandParameter="{Binding}" />
            <MenuItem Header="Version Before First Change With Version of Last Changeset"
                        Command="{Binding Path=DataContext.CompareInitialVersionWithLatestChangeCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl} } }"
                        CommandParameter="{Binding}" />
        </MenuItem>
        <Separator />
        <MenuItem Header="Exclude Changeset"
                  Command="{Binding Path=DataContext.ExcludeChangesetCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl} } }"
                  CommandParameter="{Binding}" />
        <MenuItem Header="Exclude File" 
                  Command="{Binding Path=DataContext.ExcludeFileCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl} } }"
                  CommandParameter="{Binding}" />
    </ContextMenu>

  </UserControl.Resources>
  <Grid>
    <ListView Name="ReviewItems" SelectedItem="{Binding SelectedItem}">
      <ListView.View>
        <GridView local:GridViewColumns.DisplayMemberMember="DisplayMember"
                  local:GridViewColumns.HeaderTextMember="HeaderText" 
                  local:GridViewColumns.ColumnsSource="{Binding Columns}">

          <GridView.ColumnHeaderContainerStyle>
            <Style TargetType="GridViewColumnHeader">
              <Setter Property="HorizontalContentAlignment" Value="Left"></Setter>
              <Setter Property="Padding" Value="5,0,5,0" />
            </Style>
          </GridView.ColumnHeaderContainerStyle>
        </GridView>
      </ListView.View>
      <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
          <Setter Property="local:ListViewItemClickBehavior.DoubleClick"
                  Value="{Binding DataContext.SelectItemCommand, RelativeSource={RelativeSource AncestorType={x:Type ListView}}}" />
          <Setter Property="ContextMenu" Value="{StaticResource ReviewItemMenu}" />
        </Style>
      </ListView.ItemContainerStyle>
      <ListView.GroupStyle>
        <GroupStyle>
          <GroupStyle.ContainerStyle>
            <Style TargetType="{x:Type GroupItem}">
              <Setter Property="Margin" Value="0,0,0,5" />
              <Setter Property="Template">
                <Setter.Value>
                  <ControlTemplate TargetType="{x:Type GroupItem}">
                        <Expander IsExpanded="{Binding Path=Items[0].IsGroupExpanded}"          
                                  BorderThickness="0,0,0,1">
                      <Expander.Header>
                        <DockPanel>
                          <TextBlock Text="{Binding Path=Items[0].Description}" Margin="5,0,5,0" />
                          <TextBlock Text="{Binding Path=ItemCount, StringFormat=({0})}" />
                        </DockPanel>
                      </Expander.Header>
                      <Expander.Content>
                        <ItemsPresenter />
                      </Expander.Content>
                    </Expander>
                  </ControlTemplate>
                </Setter.Value>
              </Setter>
            </Style>
          </GroupStyle.ContainerStyle>
        </GroupStyle>
      </ListView.GroupStyle>
    </ListView>
  </Grid>
</UserControl>